//
//  ShopMainViewController.m
//  BaseFrame
//
//  Created by wingfac on 2017/8/9.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "ShopMainViewController.h"
#import "ShopMainClassifyCell.h"


@interface ShopMainViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UIImageView *headerImgView;

@end

@implementation ShopMainViewController
//{
//    BOOL state;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"店铺信息";
    [self.view addSubview:self.tableView];
        
    UIButton * rightButton = [[UIButton alloc]init];
    rightButton.size = CGSizeMake(40, 20);
    [rightButton setTitle:@"保存" forState:UIControlStateNormal];
    [rightButton.titleLabel setFont:DEF_FontSize_11];
    rightButton.layer.masksToBounds = YES;
    rightButton.layer.cornerRadius = 3;
    rightButton.layer.borderColor = [[UIColor whiteColor] CGColor];
    rightButton.layer.borderWidth = 1;
    [rightButton addTarget:self action:@selector(rightBarButtonItemClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    //设置barbutton
    self.navigationItem.rightBarButtonItem = rightItem;
    
}

#pragma mark - Event
- (void)leftBarButtonItemClick{

}

- (void)rightBarButtonItemClick{
    [self.view endEditing:YES];
    
}

- (void)tableHeadViewCkick{
    [self selectPhotoAlbumWithSelectPhotoHandle:^(UIImage *img) {
        self.headerImgView.image = img;
        self.headerImgView.contentMode = UIViewContentModeScaleAspectFill;
//        state = YES;
    }];
}

#pragma mark - UITableViewDelegate & UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

        return 10;

    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

        return kShopMainClassifyCellHeight;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        ShopMainClassifyCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ShopMainClassifyCell class])];
        if(!cell){
            cell =  [[ShopMainClassifyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([ShopMainClassifyCell class])];
        }
        __weak __typeof(self)weakSelf = self;
        cell.setShopImageBlock = ^(UIButton *button) {
            [weakSelf selectPhotoAlbumWithSelectPhotoHandle:^(UIImage *img) {
            [button setImage:img forState:UIControlStateNormal];
        }];
    };
        return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    
}


#pragma mark - set & get


- (UITableView *)tableView{
    if (!_tableView) {
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.sectionFooterHeight = .01;
        _tableView.sectionHeaderHeight = .01;
        _tableView.tableHeaderView = self.headerImgView;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.backgroundColor = [UIColor whiteColor];

        
    }
    return _tableView;
}

- (UIImageView *)headerImgView{
    if (!_headerImgView) {
        _headerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 130/WIDTH_5S_SCALE)];
        _headerImgView.image = [UIImage imageNamed:@"button_mapadd"];
        _headerImgView.backgroundColor = getColor(@"f1f2f6");
        _headerImgView.contentMode = UIViewContentModeCenter;
        _headerImgView.layer.masksToBounds = YES;
        _headerImgView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tableHeadViewCkick)];
        [_headerImgView addGestureRecognizer:tap];
    }
    return _headerImgView;
}

@end
